package com.warmheart.base.session;

import com.warmheart.base.entity.Operator;

/**
 * 
 * @ClassName: SessionLocalUtils
 * @Description: 本地高速缓存类
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 */
public final class SessionLocalUtils {

    // 登录信息缓存
    private static final ThreadLocal<Operator> threadLocal = new ThreadLocal<Operator>();

    /**
     * 
     * @Title: setOperator
     * @Description: 设置登录信息到本地缓存
     * @author ZhangJianyang
     * @param operator
     */
    public static void setOperator(Operator operator) {

        threadLocal.set(operator);

    }

    /**
     * 
     * @Title: getOperator
     * @Description: 获取本地用户缓存
     * @author ZhangJianyang
     * @return
     */
    public static Operator getOperator() {
        if (threadLocal != null)
            return threadLocal.get();
        else
            throw new RuntimeException("本地缓存异常");
    }

    /**
     * 
     * @Title: removeOperator
     * @Description: 清空本地缓存
     * @author ZhangJianyang
     */
    public static void removeOperator() {

        if (threadLocal != null)
            threadLocal.remove();
        else
            throw new RuntimeException("本地缓存异常");
    }
}